<template>
  <div class="historicalhistory">
    <div class="remov">
         <router-link
        to="/userinfo"
        tag="i"
        class="iconfont icon-fanhui"
      ></router-link>
      <span @click="removData">清空</span>
    </div>

    <div class="lists">
      <div class="entry" v-for="(item,index) in newdata" :key="index">
        <router-link
          :to="{ name: 'productdetails', query: { data: item } }"
          tag="div"
          class="en-top"
        >
          <div
            class="img"
            :style="{
              background:
                'url(' + item.logImg[0] + ') no-repeat center / cover',
            }"
          >
            <span style="">{{ item.category }}</span>
          </div>
          <div class="txt">
            <h2>{{ item.title }}</h2>
            <span class="content">{{ item.content }}</span>
            <div class="pers">
              <img :src="item.img" alt="" />
              <span
                >￥<em>{{ item.price }}</em
                >起</span
              >
            </div>
          </div>
        </router-link>

        
      </div>
    </div>
  </div>
</template>

<script>
import { datas } from "../api/home";

export default {
  data() {
    return {
      datalists: [],
      dataIndex: [],
      newdata:[]
    };
  },
  methods: {
    getDatas() {
      datas().then((datas) => {
        // console.log(datas);
        this.datalists = datas.Attractions;

        // console.log(this.dataIndex);
        // console.log(this.datalists);

        let ids = localStorage.getItem("idArray");
        for (let i = 0; i < ids.length; i++) {
          if (parseInt(ids[i])) {
            this.dataIndex.push(Number(ids[i]));
          }
        }
        // 去重id
        this.dataIndex = new Set(this.dataIndex)
        for (const id of this.dataIndex) {
          this.datalists.forEach(item => {
                if (item.id==id) {
                    this.newdata.push(item)
                }
            });
        }
      });
    },

    
    removData(){
        localStorage.setItem("idArray",null)
        this. newdata=[]
    }
    
  },
  
  created() {
    this.getDatas();
    // console.log(this.dataIndex);
  },
};


</script>

<style lang="scss" scoped>
.historicalhistory {
  .lists {
    .entry {
      margin-top: 10px;
      padding: 9px 15px 0;
      background-color: #fff;
      .en-top {
        display: flex;
        justify-content: space-between;
        padding-bottom: 9px;

        .img {
          width: 105px;
          height: 105px;
          position: relative;
          background-position: center;
          span {
            display: block;
            position: absolute;
            border-bottom-right-radius: 3px;
            height: 25.48px;
            padding: 3.5px 8.5px;
            background-color: #3bcdc3;
            color: #fff;
            font-size: 14px;
            top: 0;
            left: 0;
            box-sizing: border-box;
          }
        }
        .txt {
          flex: 1;
          padding-left: 15px;
          color: #333;
          h2 {
            font-weight: normal;
            font-size: 16px;
          }
          span.content {
            font-size: 12px;
            color: #999;
            overflow: hidden;
            display: -webkit-box;
            text-overflow: ellipsis;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            margin-top: 8px;
            word-wrap: break-word;
          }
          .pers {
            display: flex;
            margin-top: 18px;
            justify-content: space-between;
            align-items: center;
            img {
              height: 20px;
            }
            span {
              color: #ff5341;
              display: flex;
              font-size: 12px;
              align-items: center;
              em {
                font-style: normal;
                font-weight: bold;
                font-size: 18px;
                margin-right: 3px;
              }
            }
          }
        }
      }
      .en-bot {
        border-top: 0.1px solid #eee;
        padding: 6.5px 0;
        display: flex;
        justify-content: space-between;
        p {
          font-size: 12px;
          margin-right: 60px;
          color: #999;
        }
        span {
          color: #ff5341;
          display: flex;
          font-size: 12px;
          align-items: center;
          em {
            font-style: normal;
            font-weight: bold;
            margin-right: 4px;
            font-size: 16px;
          }
        }
      }
    }
  }
  .remov {
    display: flex;
    justify-content: end;
    height: 38px;
    align-items: center;
    border-bottom: 1px solid #ddd;
    span {
      margin-right: 15px;
      font-size: 14px;
      color: #999;
    }
     i {
      position: absolute;
      left: 10px;
        color: #80d7d1;
      font-size: 20px;
    }
  }
}
</style>